package com.alibaba.nacos.config.server.jpa.entity;

import java.io.Serializable;
import java.time.LocalDateTime;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Lob;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;

/**
 * @author
 * @date 2020-03-08 23:31
 * 多租户改造
 */
@Entity
@Table(name = "NACOS_HIS_CONFIG_INFO", indexes = {
        @Index(name = "IDX_GMT_CREATE", columnList = "GMT_CREATE"),
        @Index(name = "IDX_GMT_MODIFIED", columnList = "GMT_MODIFIED"),
        @Index(name = "IDX_DID", columnList = "DATA_ID"),
})
public class HisConfigInfoEntity implements Serializable, IEntity {

    private static final long serialVersionUID = 1L;

    public HisConfigInfoEntity() {
    }

    /**
     * app_name
     */
    @Column(name = "APP_NAME")
    private String appName;

    @Column(name = "ID", nullable = false)
    private Long id;

    @Column(name = "CONTENT", nullable = false)
    @Lob
    private String content;

    @Column(name = "DATA_ID", nullable = false)
    private String dataId;

    @Column(name = "GMT_CREATE", nullable = false)
    @CreatedDate
    private LocalDateTime gmtCreate;

    @Column(name = "GMT_MODIFIED", nullable = false)
    @LastModifiedDate
    private LocalDateTime gmtModified;

    @Column(name = "GROUP_ID", nullable = false)
    private String groupId;

    @Column(name = "MD5")
    private String md5;

    @Column(name = "NID", nullable = false)
    @Id
    @GeneratedValue(generator = "snowflake")
    @GenericGenerator(name = "snowflake", strategy = "com.alibaba.nacos.config.server.jpa.IdGenerator")
    private Long nid;

    @Column(name = "OP_TYPE")
    private String opType;

    @Column(name = "SRC_IP")
    private String srcIp;

    @Column(name = "SRC_USER")
    @Lob
    private String srcUser;

    /**
     * 租户字段
     */
    @Column(name = "TENANT_ID")
    private String tenantId;

    public HisConfigInfoEntity setAppName(String appName) {
        this.appName = appName;
        return this;
    }

    public String getAppName() {
        return appName;
    }

    public HisConfigInfoEntity setContent(String content) {
        this.content = content;
        return this;
    }

    public String getContent() {
        return content;
    }

    public HisConfigInfoEntity setDataId(String dataId) {
        this.dataId = dataId;
        return this;
    }

    public String getDataId() {
        return dataId;
    }

    public HisConfigInfoEntity setGmtCreate(LocalDateTime gmtCreate) {
        this.gmtCreate = gmtCreate;
        return this;
    }

    public LocalDateTime getGmtCreate() {
        return gmtCreate;
    }

    public HisConfigInfoEntity setGmtModified(LocalDateTime gmtModified) {
        this.gmtModified = gmtModified;
        return this;
    }

    public LocalDateTime getGmtModified() {
        return gmtModified;
    }

    public HisConfigInfoEntity setGroupId(String groupId) {
        this.groupId = groupId;
        return this;
    }

    public String getGroupId() {
        return groupId;
    }

    public HisConfigInfoEntity setMd5(String md5) {
        this.md5 = md5;
        return this;
    }

    public String getMd5() {
        return md5;
    }

    public HisConfigInfoEntity setNid(Long nid) {
        this.nid = nid;
        return this;
    }

    public Long getNid() {
        return nid;
    }

    public HisConfigInfoEntity setOpType(String opType) {
        this.opType = opType;
        return this;
    }

    public String getOpType() {
        return opType;
    }

    public HisConfigInfoEntity setSrcIp(String srcIp) {
        this.srcIp = srcIp;
        return this;
    }

    public String getSrcIp() {
        return srcIp;
    }

    public HisConfigInfoEntity setSrcUser(String srcUser) {
        this.srcUser = srcUser;
        return this;
    }

    public String getSrcUser() {
        return srcUser;
    }

    public HisConfigInfoEntity setTenantId(String tenantId) {
        this.tenantId = tenantId;
        return this;
    }

    public String getTenantId() {
        return tenantId;
    }

    /**
     * get id
     *
     * @return id
     */
    public Long getId() {
        return id;
    }

    /**
     * set id
     *
     * @param id id
     */
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("HisConfigInfoEntity = {");

        if (appName != null) {
            sb.append("appName = ").append(appName).append(", ");
        }
        if (content != null) {
            sb.append("content = ").append(content).append(", ");
        }
        if (dataId != null) {
            sb.append("dataId = ").append(dataId).append(", ");
        }
        if (gmtCreate != null) {
            sb.append("gmtCreate = ").append(gmtCreate).append(", ");
        }
        if (gmtModified != null) {
            sb.append("gmtModified = ").append(gmtModified).append(", ");
        }
        if (groupId != null) {
            sb.append("groupId = ").append(groupId).append(", ");
        }
        if (id != null) {
            sb.append("id = ").append(id).append(", ");
        }
        if (md5 != null) {
            sb.append("md5 = ").append(md5).append(", ");
        }
        if (nid != null) {
            sb.append("nid = ").append(nid).append(", ");
        }
        if (opType != null) {
            sb.append("opType = ").append(opType).append(", ");
        }
        if (srcIp != null) {
            sb.append("srcIp = ").append(srcIp).append(", ");
        }
        if (srcUser != null) {
            sb.append("srcUser = ").append(srcUser).append(", ");
        }
        if (tenantId != null) {
            sb.append("tenantId = ").append(tenantId);
        }

        sb.append("}");
        return sb.toString();
    }

    @Override
    public void setPK(Long id) {
        setNid(id);
    }

    @Override
    public Long getPk() {
        return nid;
    }
}
